package com.zhangxun.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhangxun.domain.HotSearch;
import com.zhangxun.mapper.HotSearchMapper;
import com.zhangxun.service.HotSearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
* @author 张循
* @description 针对表【hot_search(热搜)】的数据库操作Service实现
* @createDate 2023-01-05 18:32:47
*/
@Service
public class HotSearchServiceImpl extends ServiceImpl<HotSearchMapper, HotSearch>
    implements HotSearchService{

    @Autowired
    private HotSearchMapper hotSearchMapper;

    @Override
    public Page<HotSearch> selectPage(Page<HotSearch> page, HotSearch hotSearch) {

        page = hotSearchMapper.selectPage(page,new LambdaQueryWrapper<HotSearch>()
                .like(StringUtils.hasText(hotSearch.getTitle()),HotSearch::getTitle,hotSearch.getTitle())
                .eq(ObjectUtil.isNotNull(hotSearch.getStatus()),HotSearch::getStatus,hotSearch.getStatus())
                .eq(ObjectUtil.isNotNull(hotSearch.getContent()),HotSearch::getContent,hotSearch.getContent()));

        return page;


    }

    @Override
    public List<HotSearch> selectByStatus(Integer number) {
        List<HotSearch> hotSearches = hotSearchMapper.selectList(new LambdaQueryWrapper<HotSearch>()
                .select(HotSearch::getHotSearchId,HotSearch::getTitle)
                .eq(HotSearch::getStatus, 1)
                .last("limit " + number));

        return hotSearches;
    }

}




